package com.gmall.service.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

@Configuration
public class RedissonConfig {

    @Bean(destroyMethod="shutdown")
    RedissonClient redisson() throws IOException {
        //1、创建配置
        Config config = new Config();
        config//.useReplicatedServers()//主从
                //.useSentinelServers()//哨兵模式
               //.useClusterServers()//集群
                .useSingleServer()//单机
                .setAddress("redis://localhost:6379");
        return Redisson.create(config);
    }

    RedissonClient redisson1() throws IOException {
        //1、创建配置
        Config config = new Config();
        config.useSentinelServers()//哨兵模式
                .setMasterName("redis://localhost:6379")
                .addSentinelAddress("redis://localhost:26379","redis://localhost:26380","redis://localhost:26381");
        return Redisson.create(config);
    }

    RedissonClient redisson2() throws IOException {
        //1、创建配置
        Config config = new Config();
        config.useReplicatedServers()//主从
                .addNodeAddress("redis://localhost:6379","redis://localhost:6380");
                return Redisson.create(config);
    }

    RedissonClient redisson3() throws IOException {
        //1、创建配置
        Config config = new Config();
        config.useClusterServers()//Cluster
                .addNodeAddress("redis://localhost:6380","redis://localhost:6381","redis://localhost:6382");
        return Redisson.create(config);
    }
}

